import request from '@/utils/request'

/**
 * 批量启用
 * @param {*} ids
 * @returns
 */
export function enableTask(ids) {
  return request({
    url: '/api/v1/ctmMarketTask/enable',
    method: 'PUT',
    data: ids
  })
}

/**
 * 停用
 * @param {*} data
 * @returns
 */
export function disabledTask(data) {
  return request({
    url: '/api/v1/ctmMarketTask/disable',
    method: 'PUT',
    data
  })
}
/**
 * 取消分配
 * @param {*} data
 * @returns
 */
export function undistributedTask(data) {
  return request({
    url: '/api/v1/ctmMarketTask/cancelAlloc',
    method: 'PUT',
    data
  })
}
/**
 * 分配负责人
 * @param {*} data
 * @returns
 */
export function distributedTask(data) {
  return request({
    url: '/api/v1/ctmMarketTask/alloc',
    method: 'PUT',
    data
  })
}

/**
 * 获取详情
 * @param {*} id
 * @returns
 */
export function detailTask(id) {
  return request({
    url: `/api/v1/ctmMarketTask/${id}`,
    method: 'GET'
  })
}

/**
 * 新增
 * @param {*} data
 * @returns
 */
export function addTask(data) {
  return request({
    url: '/api/v1/ctmMarketTask',
    method: 'POST',
    data
  })
}

/**
 * 编辑
 * @param {*} data
 * @returns
 */
export function editTask(data) {
  return request({
    url: '/api/v1/ctmMarketTask',
    method: 'PUT',
    data
  })
}
/**
 * 下载模板
 * @returns
 */
export function downTemplate(filename) {
  return request({
    url: '/api/v1/ctmMarketTask/downloadImportModel',
    method: 'GET',
    responseType: 'blob'
  }).then(res => {
    const a = document.createElement('a')
    const tmp = URL.createObjectURL(res)
    a.href = tmp
    a.download = filename
    a.click()
    setTimeout(() => {
      URL.revokeObjectURL(tmp)
    }, 30 * 1000)
    return res
  })
}

/**
 * 分配导入 下载模板
 * @returns
 */
export function downAllocateTemplate(filename) {
  return request({
    url: '/api/v1/ctmMarketTask/downloadImportAllocModel',
    method: 'GET',
    responseType: 'blob'
  }).then(res => {
    const a = document.createElement('a')
    const tmp = URL.createObjectURL(res)
    a.href = tmp
    a.download = filename
    a.click()
    setTimeout(() => {
      URL.revokeObjectURL(tmp)
    }, 30 * 1000)
    return res
  })
}

/**
 * 批量变更客户经理 下载模板
 * @returns
 */
export function downChangePersonTemplate(filename) {
  return request({
    url: '/api/v1/ctmMarketTask/downloadImportAllocModel',
    method: 'GET',
    responseType: 'blob'
  }).then(res => {
    const a = document.createElement('a')
    const tmp = URL.createObjectURL(res)
    a.href = tmp
    a.download = filename
    a.click()
    setTimeout(() => {
      URL.revokeObjectURL(tmp)
    }, 30 * 1000)
    return res
  })
}

/**
 * 变更责任人
 * @param {*} data 
 * @returns 
 */
export function personChange(data) {
  return request({
    url: '/api/v1/ctmMarketTask/changePerson',
    method: 'PUT',
    data
  })
}